import {defineStore} from "pinia";
import {getCategories, getHomeHouseList, getHotCity} from "@/services";

const useHome = defineStore('home', {
   state: () => ({
      hotCity: [],
      categories: [],
      houseList: [],
      houseListPage: 0
   }),
   getters: {},
   actions: {
      async fetchHotCity() {
         const res = await getHotCity()
         this.hotCity = res.data
      },
      async fetchCategories() {
         const res = await getCategories()
         this.categories = res.data
      },
      async fetchHouseList() {
         this.houseListPage++
         const res = await getHomeHouseList(this.houseListPage)
         this.houseList.push(...res.data)
      }
   }
})

export default useHome